/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bbstone.pisces.client.gui;

import com.bbstone.pisces.comm.gui.DirChooser;
import com.bbstone.pisces.comm.gui.TreeNodeBuilder;
import com.bbstone.pisces.config.Config;
import java.awt.CardLayout;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.apache.commons.lang3.StringUtils;

/**
 *
 * @author bbstone
 */
public class ClientMainFrame extends javax.swing.JFrame {

    /**
     * Creates new form ClientFrame2
     */
    public ClientMainFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cardPanel = new javax.swing.JPanel();
        transferPanel = new javax.swing.JPanel();
        bottomToolBar = new javax.swing.JToolBar();
        contentSplitPane = new javax.swing.JSplitPane();
        contentPanel = new javax.swing.JPanel();
        transferProgressBar = new javax.swing.JProgressBar();
        infoScrollPane = new javax.swing.JScrollPane();
        infoTextArea = new javax.swing.JTextArea();
        existsLabel = new javax.swing.JLabel();
        existsValLabel = new javax.swing.JLabel();
        receivedLabel = new javax.swing.JLabel();
        receivedValLabel = new javax.swing.JLabel();
        filepathLabel = new javax.swing.JLabel();
        filecatLabel = new javax.swing.JLabel();
        filesizeLabel = new javax.swing.JLabel();
        checksumLabel = new javax.swing.JLabel();
        filepathTextField = new javax.swing.JTextField();
        checksumTextField = new javax.swing.JTextField();
        filecatTextField = new javax.swing.JTextField();
        filesizeTextField = new javax.swing.JTextField();
        transferButton = new javax.swing.JButton();
        logsScrollPane = new javax.swing.JScrollPane();
        logsTextArea = new javax.swing.JTextArea();
        skipsLabel = new javax.swing.JLabel();
        skipsValLabel = new javax.swing.JLabel();
        connectButton = new javax.swing.JButton();
        treeSplitPane = new javax.swing.JSplitPane();
        serverDirScrollPane = new javax.swing.JScrollPane();
        serverDirTree = new javax.swing.JTree(TreeNodeBuilder.buildServerTreeNode());
        clientDirScrollPane = new javax.swing.JScrollPane();
        clientDirTree = new javax.swing.JTree(TreeNodeBuilder.buildTreeNodes(Config.clientDir(), TreeNodeBuilder.clientRootDisplayName()));
        configPanel = new javax.swing.JPanel();
        infoScrollPane1 = new javax.swing.JScrollPane();
        infoTextArea1 = new javax.swing.JTextArea();
        portLabel = new javax.swing.JLabel();
        portTextField = new javax.swing.JTextField();
        hostLabel = new javax.swing.JLabel();
        hostTextField = new javax.swing.JTextField();
        clientDirLabel = new javax.swing.JLabel();
        clientDirTextField = new javax.swing.JTextField();
        selectDirButton = new javax.swing.JButton();
        msgScrollPane = new javax.swing.JScrollPane();
        msgTextArea = new javax.swing.JTextArea();
        resetButton = new javax.swing.JButton();
        clearButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        mainMenuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        connectMenuItem = new javax.swing.JMenuItem();
        configMenuItem = new javax.swing.JMenuItem();
        transferMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        aboutMenu = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        cardPanel.setLayout(new java.awt.CardLayout());

        transferPanel.setSize(new java.awt.Dimension(100, 1));

        bottomToolBar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        bottomToolBar.setRollover(true);

        contentSplitPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        contentSplitPane.setDividerLocation(210);
        contentSplitPane.setDividerSize(5);

        contentPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        infoTextArea.setEditable(false);
        infoTextArea.setColumns(20);
        infoTextArea.setLineWrap(true);
        infoTextArea.setRows(2);
        infoTextArea.setText("The left top tree list server directory files, and the left bottom tree list client directory");
        infoTextArea.setAutoscrolls(false);
        infoTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1), null));
        infoTextArea.setDisabledTextColor(new java.awt.Color(0, 0, 255));
        infoTextArea.setEnabled(false);
        infoScrollPane.setViewportView(infoTextArea);

        existsLabel.setText("Exists: ");

        existsValLabel.setText("5");

        receivedLabel.setText("Received: ");

        receivedValLabel.setText("1/100");

        filepathLabel.setText("File Path: ");

        filecatLabel.setText("File Cat: ");

        filesizeLabel.setText("File Size:");

        checksumLabel.setText("Checksum:");

        transferButton.setText("Start Transfer");

        logsTextArea.setEditable(false);
        logsTextArea.setColumns(20);
        logsTextArea.setLineWrap(true);
        logsTextArea.setRows(5);
        logsTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1), null));
        logsScrollPane.setViewportView(logsTextArea);

        skipsLabel.setText("Skips:");

        skipsValLabel.setText("3");

        connectButton.setText("Re/Connect");

        javax.swing.GroupLayout contentPanelLayout = new javax.swing.GroupLayout(contentPanel);
        contentPanel.setLayout(contentPanelLayout);
        contentPanelLayout.setHorizontalGroup(
            contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(transferProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(infoScrollPane)
            .addGroup(contentPanelLayout.createSequentialGroup()
                .addComponent(existsLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(existsValLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(receivedLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(receivedValLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(skipsLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(skipsValLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE))
            .addGroup(contentPanelLayout.createSequentialGroup()
                .addGroup(contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checksumLabel)
                    .addComponent(filecatLabel)
                    .addComponent(filepathLabel)
                    .addComponent(filesizeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checksumTextField)
                    .addComponent(filepathTextField)
                    .addComponent(filecatTextField)
                    .addComponent(filesizeTextField)))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, contentPanelLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(connectButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(transferButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(logsScrollPane)
        );
        contentPanelLayout.setVerticalGroup(
            contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(contentPanelLayout.createSequentialGroup()
                .addComponent(infoScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(transferProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(existsLabel)
                    .addComponent(existsValLabel)
                    .addComponent(receivedLabel)
                    .addComponent(receivedValLabel)
                    .addComponent(skipsLabel)
                    .addComponent(skipsValLabel))
                .addGap(39, 39, 39)
                .addGroup(contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(filepathLabel)
                    .addComponent(filepathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(filecatLabel)
                    .addComponent(filecatTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(filesizeLabel)
                    .addComponent(filesizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checksumLabel)
                    .addComponent(checksumTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(transferButton)
                    .addComponent(connectButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(logsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE))
        );

        contentSplitPane.setBottomComponent(contentPanel);

        treeSplitPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        treeSplitPane.setDividerLocation(220);
        treeSplitPane.setDividerSize(5);
        treeSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        serverDirTree.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        serverDirScrollPane.setViewportView(serverDirTree);

        treeSplitPane.setTopComponent(serverDirScrollPane);

        clientDirTree.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        clientDirScrollPane.setViewportView(clientDirTree);

        treeSplitPane.setRightComponent(clientDirScrollPane);

        contentSplitPane.setLeftComponent(treeSplitPane);

        javax.swing.GroupLayout transferPanelLayout = new javax.swing.GroupLayout(transferPanel);
        transferPanel.setLayout(transferPanelLayout);
        transferPanelLayout.setHorizontalGroup(
            transferPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(bottomToolBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(contentSplitPane)
        );
        transferPanelLayout.setVerticalGroup(
            transferPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, transferPanelLayout.createSequentialGroup()
                .addComponent(contentSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bottomToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        cardPanel.add(transferPanel, "transferCard");

        infoTextArea1.setEditable(false);
        infoTextArea1.setBackground(new java.awt.Color(238, 238, 238));
        infoTextArea1.setColumns(20);
        infoTextArea1.setLineWrap(true);
        infoTextArea1.setRows(5);
        infoTextArea1.setText("Configuration Panel setup client received files whiches storage directory, server host, server port for listening, SSL enabled or not.");
        infoTextArea1.setAutoscrolls(false);
        infoTextArea1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1), null));
        infoTextArea1.setDisabledTextColor(new java.awt.Color(0, 51, 255));
        infoTextArea1.setEnabled(false);
        infoScrollPane1.setViewportView(infoTextArea1);

        portLabel.setText("Port: ");

        portTextField.setText("8899");

        hostLabel.setText("Host: ");

        clientDirLabel.setText("Client Dir: ");

        selectDirButton.setText("Choose ...");
        selectDirButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectDirButtonActionPerformed(evt);
            }
        });

        msgTextArea.setEditable(false);
        msgTextArea.setColumns(20);
        msgTextArea.setLineWrap(true);
        msgTextArea.setRows(5);
        msgTextArea.setAutoscrolls(false);
        msgTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1), null));
        msgTextArea.setDisabledTextColor(new java.awt.Color(255, 51, 51));
        msgTextArea.setEnabled(false);
        msgScrollPane.setViewportView(msgTextArea);

        resetButton.setText("Reset");
        resetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetButtonActionPerformed(evt);
            }
        });

        clearButton.setText("Clear");
        clearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButtonActionPerformed(evt);
            }
        });

        saveButton.setText("Save");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout configPanelLayout = new javax.swing.GroupLayout(configPanel);
        configPanel.setLayout(configPanelLayout);
        configPanelLayout.setHorizontalGroup(
            configPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(infoScrollPane1)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, configPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(configPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(configPanelLayout.createSequentialGroup()
                        .addGroup(configPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(portLabel)
                            .addComponent(hostLabel)
                            .addComponent(clientDirLabel))
                        .addGroup(configPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(configPanelLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(clientDirTextField)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(selectDirButton, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(configPanelLayout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addGroup(configPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(hostTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(portTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addComponent(msgScrollPane)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, configPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 513, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(resetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        configPanelLayout.setVerticalGroup(
            configPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(configPanelLayout.createSequentialGroup()
                .addComponent(infoScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(configPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(portLabel)
                    .addComponent(portTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(configPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(hostLabel)
                    .addComponent(hostTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(configPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clientDirLabel)
                    .addComponent(clientDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(selectDirButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(configPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(resetButton)
                    .addComponent(clearButton)
                    .addComponent(saveButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(msgScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(124, Short.MAX_VALUE))
        );

        cardPanel.add(configPanel, "configCard");
        initConfigFormData();

        fileMenu.setText("File");

        connectMenuItem.setText("Connect");
        fileMenu.add(connectMenuItem);

        configMenuItem.setText("Configuration");
        configMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(configMenuItem);

        transferMenuItem.setText("Transfer");
        transferMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transferActionPerformed(evt);
            }
        });
        fileMenu.add(transferMenuItem);

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        mainMenuBar.add(fileMenu);

        aboutMenu.setText("Help");

        jMenuItem3.setText("Docs");
        aboutMenu.add(jMenuItem3);

        jMenuItem4.setText("About");
        aboutMenu.add(jMenuItem4);

        mainMenuBar.add(aboutMenu);

        setJMenuBar(mainMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(cardPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(cardPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void selectDirButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectDirButtonActionPerformed
        DirChooser dirChooser = new DirChooser(this.clientDirTextField);
        int val = dirChooser.getDirChooser().showOpenDialog(null);
        dirChooser.setVal(val);
    }//GEN-LAST:event_selectDirButtonActionPerformed

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
        // TODO read form data from config.properties
        // clear msg text
        this.msgTextArea.setText(null);
        //
        this.hostTextField.setText(Config.host());
        this.portTextField.setText(String.valueOf(Config.port()));
        this.clientDirTextField.setText(Config.clientDir());

    }//GEN-LAST:event_resetButtonActionPerformed

    private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
        // clear msg text
        this.msgTextArea.setText(null);
        //
        this.portTextField.setText(null);
        this.hostTextField.setText(null);
        this.clientDirTextField.setText(null);
    }//GEN-LAST:event_clearButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        //clear message area
        this.msgTextArea.setText(null);
        StringBuilder sbu = new StringBuilder();
        // validate form data
        if (StringUtils.isAnyBlank(this.portTextField.getText(), this.hostTextField.getText(), this.clientDirTextField.getText())) {
            sbu.append("port/host/server dir cannot be empty.");
            this.msgTextArea.setText(sbu.toString());
            return ;
        }
        if (!Files.isDirectory(Paths.get(this.clientDirTextField.getText()))) {
            sbu.append("Client Dir Field input path is not directory.");
            this.msgTextArea.setText(sbu.toString());
            return ;
        }
        // do save procedure
        String host = StringUtils.trim(this.hostTextField.getText());
        String port = StringUtils.trim(this.portTextField.getText());
        String clientDir = StringUtils.trim(this.clientDirTextField.getText());
        Config.setProperty(Config.SERVER_HOST_KEY, host);
        Config.setProperty(Config.SERVER_PORT_KEY, port);
        Config.setProperty(Config.CLIENT_DIR_KEY, clientDir);
        Config.saveUpdate(); // batch save changes to file

        this.msgTextArea.setText("configurtion saved OK.");
    }//GEN-LAST:event_saveButtonActionPerformed

    private void configMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configMenuItemActionPerformed
        CardLayout cardLayout = (CardLayout)cardPanel.getLayout();
        cardLayout.show(cardPanel, "configCard");
        //cardLayout.show(basePanel, "transferPanel");
    }//GEN-LAST:event_configMenuItemActionPerformed

    private void transferActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transferActionPerformed
        CardLayout cardLayout = (CardLayout)cardPanel.getLayout();
        cardLayout.show(cardPanel, "transferCard");
    }//GEN-LAST:event_transferActionPerformed

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void initConfigFormData() {
        this.hostTextField.setText(Config.host());
        this.portTextField.setText(String.valueOf(Config.port()));
        this.clientDirTextField.setText(Config.clientDir());
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ClientMainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ClientMainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ClientMainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ClientMainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ClientMainFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu aboutMenu;
    private javax.swing.JToolBar bottomToolBar;
    private javax.swing.JPanel cardPanel;
    private javax.swing.JLabel checksumLabel;
    private javax.swing.JTextField checksumTextField;
    private javax.swing.JButton clearButton;
    private javax.swing.JLabel clientDirLabel;
    private javax.swing.JScrollPane clientDirScrollPane;
    private javax.swing.JTextField clientDirTextField;
    private javax.swing.JTree clientDirTree;
    private javax.swing.JMenuItem configMenuItem;
    private javax.swing.JPanel configPanel;
    private javax.swing.JButton connectButton;
    private javax.swing.JMenuItem connectMenuItem;
    private javax.swing.JPanel contentPanel;
    private javax.swing.JSplitPane contentSplitPane;
    private javax.swing.JLabel existsLabel;
    private javax.swing.JLabel existsValLabel;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JLabel filecatLabel;
    private javax.swing.JTextField filecatTextField;
    private javax.swing.JLabel filepathLabel;
    private javax.swing.JTextField filepathTextField;
    private javax.swing.JLabel filesizeLabel;
    private javax.swing.JTextField filesizeTextField;
    private javax.swing.JLabel hostLabel;
    private javax.swing.JTextField hostTextField;
    private javax.swing.JScrollPane infoScrollPane;
    private javax.swing.JScrollPane infoScrollPane1;
    private javax.swing.JTextArea infoTextArea;
    private javax.swing.JTextArea infoTextArea1;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JScrollPane logsScrollPane;
    private javax.swing.JTextArea logsTextArea;
    private javax.swing.JMenuBar mainMenuBar;
    private javax.swing.JScrollPane msgScrollPane;
    private javax.swing.JTextArea msgTextArea;
    private javax.swing.JLabel portLabel;
    private javax.swing.JTextField portTextField;
    private javax.swing.JLabel receivedLabel;
    private javax.swing.JLabel receivedValLabel;
    private javax.swing.JButton resetButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JButton selectDirButton;
    private javax.swing.JScrollPane serverDirScrollPane;
    private javax.swing.JTree serverDirTree;
    private javax.swing.JLabel skipsLabel;
    private javax.swing.JLabel skipsValLabel;
    private javax.swing.JButton transferButton;
    private javax.swing.JMenuItem transferMenuItem;
    private javax.swing.JPanel transferPanel;
    private javax.swing.JProgressBar transferProgressBar;
    private javax.swing.JSplitPane treeSplitPane;
    // End of variables declaration//GEN-END:variables
}
